<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('新增文章')" />
<th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-article-add" action="">
		   <input name="categoryId" type="hidden" id="treeId"/>
			<div class="form-group">
				<label class="col-sm-3 control-label">所属栏目：</label>
				<div class="col-sm-8">
					<div class="input-group">
						<input name="categoryName" onclick="selectCategoryTree()" id="treeName" type="text" placeholder="请选择所属栏目" class="form-control" required> 
						 <span class="input-group-addon" onclick="selectCategoryTree()"><i class="fa fa-search"></i></span>
					</div>
				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label is-required">标题：</label>
				<div class="col-sm-8">
					<input name="title" class="form-control" type="text" required>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">摘要：</label>
				<div class="col-sm-8">
					<textarea name="summary" class="form-control" cols="" rows=""></textarea>
				</div>
			</div>
			<div class="form-group">    
                <label class="col-sm-3 control-label">主图：</label>
                <div class="col-sm-8">
                    <input type="hidden" id="image"  name="image">
                    <img class="img-sm"  th:src="@{/img/upload.png}" onclick="selectSingleMaterial()" >
                </div>
            </div>
			<div class="form-group">
				<label class="col-sm-3 control-label">内容：</label>
				<div class="col-sm-8">
					<input type="hidden" class="form-control" name="content">
					<div class="summernote" id="content"></div>
				</div>
			</div>
			
			 <div class="form-group">
				<label class="col-sm-3 control-label is-required">作者：</label>
				<div class="col-sm-3">
					<input name="author"  class="form-control" type="text" required>
				</div>
				<label class="col-sm-2 control-label is-required">排序：</label>
				<div class="col-sm-3">
				      <input name="sort"  class="form-control" type="number" required>
				</div>
			</div>
			
			<div class="form-group">
				<label class="col-sm-3 control-label">显示状态：</label>
				<div class="col-sm-3">
					<div class="radio-box" th:each="dict : ${@dict.getType('sys_show_hide')}">
						<input type="radio" th:id="${dict.dictCode}" name="status" th:value="${dict.dictValue}" th:checked="${dict.default}">
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					</div>
				</div>
				<label class="col-sm-2 control-label is-required">是否热门：</label>
				<div class="col-sm-3">
				      <div class="radio-box" th:each="dict : ${@dict.getType('shop_yes_no')}">
						<input type="radio" th:id="${dict.dictCode}" name="isHot" th:value="${dict.dictValue}" >
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					  </div>
				</div>
			</div>
			
		   <div class="form-group">    
                <label class="col-sm-3 control-label">是否轮播：</label>
                <div class="col-sm-8">
                     <div class="radio-box" th:each="dict : ${@dict.getType('shop_yes_no')}">
						<input type="radio" th:id="${dict.dictCode}" name="isShow" th:value="${dict.dictValue}" >
						<label th:for="${dict.dictCode}" th:text="${dict.dictLabel}"></label>
					  </div>
                </div>
            </div>
			
			
			
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: summernote-js" />
	<script th:inline="javascript" type="text/javascript">
		var prefix = ctx + "shop/cms/article"
		$("#form-article-add").validate({
			focusCleanup : true
		});

		function submitHandler() {
			if ($.validate.form()) {
				$.operate.save(prefix + "/add", $('#form-article-add')
						.serialize());
			}
		}

		$(function() {
			$('.summernote').summernote(
					{
						height : 250,
						lang : 'zh-CN',
						dialogsInBody : true,
						callbacks : {
							onChange : function(contents, $edittable) {
								$("input[name='" + this.id + "']")
										.val(contents);
							},
							onImageUpload : function(files) {
								var obj = this;
								var data = new FormData();
								data.append("file", files[0]);
								$.ajax({
									type : "post",
									url : ctx + "shop/upload",
									data : data,
									cache : false,
									contentType : false,
									processData : false,
									dataType : 'json',
									success : function(result) {
										if (result.code == web_status.SUCCESS) {
											$('#' + obj.id).summernote(
													'insertImage', result.url);
										} else {
											$.modal.alertError(result.msg);
										}
									},
									error : function(error) {
										$.modal.alertWarning("图片上传失败。");
									}
								});
							}
						}
					});
		});
		
		/*栏目树*/
		function selectCategoryTree() {
        	var url = ctx + "shop/cms/category/selectCategoryTree/0/0";
			var options = {
				title: '栏目选择',
				width: "380",
				url: url,
				callBack: doSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSubmit(index, layero){
			var body = $.modal.getChildFrame(index);
   			$("#treeId").val(body.find('#treeId').val());
   			$("#treeName").val(body.find('#treeName').val());
   			$.modal.close(index);
		}
		
		/*素材单选框*/
		function selectSingleMaterial() {
			var options = {
				title : '素材库',
				width : "1500",
				url : ctx + "shop/plugin/material/single",
				callBack : doSingleSubmit
			};
			$.modal.openOptions(options);
		}
		
		function doSingleSubmit(index, layero) {
			var url = layero.find("iframe")[0].contentWindow.getSelections();
		    if(url != ""){
		      $("#image").val(url);	
		      $(".img-sm").attr("src",url);	
			  $.modal.close(index);
		    }
			
		}
	</script>
</body>
</html>